<?php

use Illuminate\Container\Container;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;

if (!class_exists('\Illuminate\Database\Capsule\Manager')) {
    return;
}
$capsule = new Capsule;
$configs = config('database');


$default_config = $configs['connections'][$configs['default']];
$capsule->addConnection($default_config);

foreach ($configs['connections'] as $name => $config) {
    $capsule->addConnection($config, $name);
}

if (class_exists('\Illuminate\Events\Dispatcher')) {
    $capsule->setEventDispatcher(new Dispatcher(new Container));
}

$capsule->setAsGlobal();

$capsule->bootEloquent();
